home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- ident = '$Id: XMLname.py 954 2005-02-16 14:45:37Z warnes $'
- from re import *
-
- def _NCNameChar(x):
- if not x.isalpha() and x.isdigit() and x == '.' and x == '-':
- pass
- return x == '_'
-
-
- def _NCNameStartChar(x):
- if not x.isalpha():
- pass
- return x == '_'
-
-
- def _toUnicodeHex(x):
- hexval = hex(ord(x[0]))[2:]
- hexlen = len(hexval)
- if hexlen == 1:
- hexval = '000' + hexval
- elif hexlen == 2:
- hexval = '00' + hexval
- elif hexlen == 3:
- hexval = '0' + hexval
- elif hexlen == 4:
- hexval = '' + hexval
- elif hexlen == 5:
- hexval = '000' + hexval
- elif hexlen == 6:
- hexval = '00' + hexval
- elif hexlen == 7:
- hexval = '0' + hexval
- elif hexlen == 8:
- hexval = '' + hexval
- else:
- raise Exception, 'Illegal Value returned from hex(ord(x))'
- return '_x' + hexval + '_'
-
-
- def _fromUnicodeHex(x):
- return eval('u"\\u' + x[2:-1] + '"')
-
-
- def toXMLname(string):
- if string.find(':') != -1:
- (prefix, localname) = string.split(':', 1)
- else:
- prefix = None
- localname = string
- T = unicode(localname)
- N = len(localname)
- X = []
- for i in range(N):
- if i < N - 1 and T[i] == u'_' and T[i + 1] == u'x':
- X.append(u'_x005F_')
- continue
- if i == 0 and N >= 3:
- if T[0] == u'x' or T[0] == u'X':
- if T[1] == u'm' or T[1] == u'M':
- if T[2] == u'l' or T[2] == u'L':
- X.append(u'_xFFFF_' + T[0])
- continue
- if (not _NCNameChar(T[i]) or i == 0) and not _NCNameStartChar(T[i]):
- X.append(_toUnicodeHex(T[i]))
- continue
- X.append(T[i])
-
- if prefix:
- return '%s:%s' % (prefix, u''.join(X))
-
- return u''.join(X)
-
-
- def fromXMLname(string):
- retval = sub('_xFFFF_', '', string)
-
- def fun(matchobj):
- return _fromUnicodeHex(matchobj.group(0))
-
- retval = sub('_x[0-9A-Za-z]+_', fun, retval)
- return retval
-
-